package cn.tedu.project.oa.sys.role.controller;


import cn.tedu.project.oa.base.response.JsonResult;
import cn.tedu.project.oa.sys.role.pojo.dto.OperaRolePara;
import cn.tedu.project.oa.sys.role.pojo.dto.QueryRolePara;
import cn.tedu.project.oa.sys.role.pojo.vo.RoleVO;
import cn.tedu.project.oa.sys.role.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "03.角色管理")
@Slf4j
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 添加角色信息
     *
     * @param operateRole
     * @return JsonResult
     */
    @ApiOperation(value = "添加角色信息")
    @PostMapping("/add")
    public JsonResult add(@RequestBody OperaRolePara operateRole) {
        roleService.operateRole(operateRole);
        return JsonResult.ok();
    }

    /**
     * 删除角色信息
     *
     * @param id
     * @return JsonResult
     */
    @ApiOperation(value = "删除角色信息")
    @PostMapping("/delete/{id}")
    public JsonResult delete(@PathVariable Long id) {
        roleService.deleteRole(id);
        return JsonResult.ok();
    }

    /**
     * 编辑角色信息
     *
     * @param operateRole
     * @return JsonResult
     */
    @ApiOperation(value = "编辑角色信息")
    @PostMapping("/edit")
    public JsonResult edit(@RequestBody OperaRolePara operateRole) {
        roleService.operateRole(operateRole);
        return JsonResult.ok();
    }

    @ApiOperation(value = "获取角色列表")
    @GetMapping("/list")
    public JsonResult queryRole(QueryRolePara queryRolePara) {
        log.info("查询角色信息queryRolePara: {}", queryRolePara);
        List<RoleVO> roleList = roleService.queryRoles(queryRolePara);
        return JsonResult.ok(roleList);
    }

}
